#pragma once

namespace TerrainSystem
{
	class Terrain;
	class TgaLoader
	{
	public:
		TgaLoader(): m_iImageWidth(0), m_iImageHeight(0), m_iBitsPerPixel(0),m_iImageDataSize(0),m_pImageData(NULL){}
		virtual ~TgaLoader(void)
		{
			if( m_pImageData != NULL )
			{
				delete[] m_pImageData;
				m_pImageData = NULL;
			}
		}

		enum TGALoadError
		{
			TGA_NO_ERROR = 1,	// No Error
			TGA_BAD_FMT,		// TGA format is incorrect
			TGA_FILE_NOT_FOUND, // File was not found
			TGA_BAD_IMAGE_TYPE, // Color mapped image is not uncompressed
			TGA_BAD_DIMENSION,  // Dimension is not a power of 2
			TGA_BAD_BITS,		// Image bits is not 8, 24 or 32
			TGA_BAD_DATA		// Image data could not be loaded
		};

		TGALoadError Load( const char* pszFileName );

		int GetWidth(void) const;
		int GetHeight(void) const;
		int GetBitsPerPixel(void) const;
		int GetDataSize(void) const;

		unsigned char* GetImageData(void) const;

	private:

		int m_iImageWidth;
		int m_iImageHeight;
		int m_iBitsPerPixel;
		int m_iImageDataSize;

		unsigned char* m_pImageData;
	};

	class TerrainSerializer
	{
	public:
		//ter format is specified at http://www.planetside.co.uk/terragen/dev/tgterrain.html#size

		static bool ImportTga( Terrain* pTerrain, const char* pszFileName );
		static bool ImportTer( Terrain* pTerrain, const char* pszFileName );
		static bool ExportTer( Terrain* pTerrain, const char* pszFileName );
	};
}